package restful.struts2.app1;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

import org.junit.*;

import restful.struts2.*;

public class EchoIT extends ProtocolIT {

	@BeforeClass
	public static void setUpClass() throws Exception {
		start("app1");
	}

	@Test
	public void testEchoProtocolIsDefined() throws Exception {
		GET("/protocol.txt");
		assertThat(status, is(equalTo(200)));
		assertThat(content, containsString("POST /echo"));
		assertThat(content, containsString("GET /echo/{message}"));
		assertThat(content, containsString("PUT /echo/{message}"));
		assertThat(content, containsString("DELETE /echo/{message}"));
	}

	@Test
	public void testGetEcho() throws Exception {
		GET("/echo/hello.json");
		assertThat(status, is(equalTo(200)));
		assertThat(content, containsString("hello"));
	}

	@Test
	public void testPostEcho() throws Exception {
		POST("/echo.json", "message", "hello");
		assertThat(status, is(equalTo(200)));
		assertThat(content, containsString("hello"));
	}

	@Test
	public void testPutEcho() throws Exception {
		PUT("/echo/hello.json");
		assertThat(status, is(equalTo(200)));
		assertThat(content, containsString("hello"));
	}

	@Test
	public void testDeleteEcho() throws Exception {
		DELETE("/echo/hello.json");
		assertThat(status, is(equalTo(200)));
		assertThat(content, containsString("hello"));
	}

}
